<?php
require_once("model/loginBD.php");
function add_keepBD($id_skill) {
	$query = "INSERT INTO keep (id_user,id_skill) 
			  VALUES ( '".$_SESSION['id_user']."','".$id_skill."' )";
	logIn();
	$rs = mysql_query($query); //or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	if (!$rs)
		return false;
	return true;
}

function view_keepBD($id_skill) {
	$query = "SELECT id_user, id_skill FROM keep
			  WHERE id_user = '".$_SESSION['id_user']."'
			  AND id_skill = '".$id_skill."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][] = $row['id_user'];
			$tab['id_skill'][] = $row['id_skill'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function view_keep_by_skillBD($id_skill) {
	$query = "SELECT id_user, id_skill FROM keep
			  WHERE id_skill = '".$id_skill."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][] = $row['id_user'];
			$tab['id_skill'][] = $row['id_skill'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function view_simple_keepBD() {
	$query = "SELECT id_user, id_skill FROM keep
			  WHERE id_user = '".$_SESSION['id_user']."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][] = $row['id_user'];
			$tab['id_skill'][] = $row['id_skill'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function delete_keep_db($id_skill) {
	$query = "DELETE FROM keep WHERE (id_user = '".$_SESSION['id_user']."') AND (id_skill = '".$id_skill."')";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}

function delete_keep_user($id_user) {
	$query = "DELETE FROM keep WHERE (id_user = '".$id_user."')";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}


?>